import { ref } from 'vue'
import { defineStore } from 'pinia'
import baseAPI from '../utils/api'

export const uploadStore = defineStore('upload', () => {
  // 对话框开启变量
  const isopendialog = ref(false)
  //   下载模板名
  const downloadName = ref('')
  //   上传url
  const importUrl = ref('')
  //   对话框标题
  const dialogName = ref('')
  // 对话框开启函数
  const changeopen = (name: string, url: string, dialogname: string) => {
    importUrl.value = url
    downloadName.value = name
    dialogName.value = dialogname
    isopendialog.value = true
  }
  // 对话框关闭函数
  const closeDialog = () => {
    isopendialog.value = false
  }
  //   导入函数
  const importData = (file: any) => {
    baseAPI.teacherBaseAPI.upload(importUrl.value, file)
  }

  return { changeopen, isopendialog, downloadName, importData, dialogName, closeDialog }
})
